<?php
// FileFind - ftp/shares indexing and search php engine,
// http://project.ffind.ru
//
// Module: lib/lib.info.php
// Description: Information functions, about php/mysql.
// Copyright (c) 2003-2008 Rage Steel, www.gt2.ru
// ----------------------------------------------
// $Id$

require_once('./lib/class.sql.php');

// Returns an array of system information
function get_system_info() {
  global $sqlconn;

  $result = array(
    'php' => array(
      'version' => phpversion(),
      'extensions' => get_loaded_extensions(),
      'sapi' => php_sapi_name()
    ),

    'mysql' => $sqlconn->get_info(),

    'os' => array(
      'name' => php_uname('s'),
      'host' => php_uname('n'),
      'release' => php_uname('r'),
      'version' => php_uname('v'),
      'machine' => php_uname('m')
    )
  );

  if (isset($_SERVER['SERVER_SOFTWARE'])) {
   if (preg_match('/^Apache\/(\S+\s\(.+\))\s/', $_SERVER['SERVER_SOFTWARE'], $apache)) {
      $result['apache'] = array(
        'version' => $apache[1],
        'modules' => apache_get_modules()
      );
    }
  }

  return $result;
} // get_system_info

// Return total query count and date of first query
// @param string MySQL Date, does not escaped
// WARNING date of first query will be NULL if count = 0;
function get_search_info($to_date = NULL) {
  $sq = new CSqlQ('tbl_query');
  $sq->add_calc_field('count', 'COUNT(*)');
  $sq->add_calc_field('start_date', 'MIN(`query_datetime`)');
  if (!is_null($to_date)) {
    $sq->where = '`query_datetime` < "' . $to_date . '"';
  }
  $sq->exec_select();
  return $sq->fetch_assoc();
} // get_search_info

?>